//
//  JHSMutiSickController.m
//  detailVC
//
//  Created by chenWei on 2017/3/23.
//  Copyright © 2017年 陈伟. All rights reserved.
//

#import "JHSMutiSickController.h"
#import "JHSSyndromeTypeModel.h"

@interface JHSMutiSickController ()
@property (nonatomic,weak) UIButton *navBtn;


@end

@implementation JHSMutiSickController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.modelArr=[NSArray array];
    self.modelArrM=[NSMutableArray array];
    self.selectModelArr=[NSMutableArray array];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    [self loadMutiSickData];  //加载网络数据
    [self setupUI];
    
    
}

-(void) setupUI{
    
    
}

#pragma mark - tableView代理方法
//MARK:选中不同cell的事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //获取当前cell
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    //确定按钮
    UIBarButtonItem *navBtn = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(clickedItemBtn:)];
    navBtn.tintColor=[UIColor whiteColor];
    self.navigationItem.rightBarButtonItem = navBtn;
    
    UIButton *btn = [[UIButton alloc]init];
    [btn setImage:[UIImage imageNamed:@"login_protocol"] forState:UIControlStateNormal];
    [cell.contentView addSubview:btn];
    btn.frame = CGRectMake(330, 10, 30, 30);
    
    //判断这个model在不在模型数组里面
    //    _modelArr
    JHSSyndromeTypeModel *model=[JHSSyndromeTypeModel yy_modelWithJSON:_modelArr[indexPath.row]];
    
    
    
    if (_modelArrM==nil) {
        [_modelArrM addObject:model];
        
    }else{
        if (![_modelArrM containsObject:model]) {
            [_modelArrM addObject:model];
            [_selectModelArr addObject:model];
        }
    }
    
    
    //cell取消选中
    [tableView deselectRowAtIndexPath:indexPath animated:NO];

}

//MARK:点击了确认按钮
-(void)clickedItemBtn:(UIBarButtonItem *)btn{
    
    [self.delegate setMutiSick:self withModels:_modelArrM.copy];
    
    [self.navigationController popViewControllerAnimated:YES];
}


-(void) loadMutiSickData{
    
    NSString *url = @"http://iosapi.itcast.cn/doctor/complicationList.json.php";
    //改成首类模型的ci1_id、大类的ci2_id
    
    NSInteger ci2=[self.sicknessTypeModel.ci2_id integerValue];
    
    NSDictionary *parameters2 = @{@"page":@1,@"page_size":@15,@"ci1_id":@(self.ci1_ID),@"ci2_id":@(ci2)};
//
    NSLog(@"------para2------%@",parameters2);

    
//    NSDictionary *parameters = @{@"page":@1,@"page_size":@15,@"ci1_id":@1,@"ci2_id":@3};
//    
//    
//        NSLog(@"------para------%@",parameters);
    
    [JHSSyndromeTypeModel syndromeTypeNetDataWithURL:url withParameters:parameters2 withSuccessBlock:^(id responceBoby) {

    
            _modelArr=responceBoby;
            [self.tableView reloadData];
        
    } withFailureBlock:^(NSError *error) {
        
        NSLog(@"JHSSickTypeController网络请求失败");
    }];
    

    
}

#pragma mark - 数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _modelArr.count;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    JHSSyndromeTypeModel *modelDic=[JHSSyndromeTypeModel yy_modelWithJSON:_modelArr[indexPath.row]];
    
    cell.textLabel.text = [NSString stringWithFormat:@"%@",modelDic.complication_name];
    
    
    return cell;
    
}





@end
